home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
DOS Vuser Deluxe 2003 October
/
DOS Vuser Deluxe 2003 Oct - Disc 1.iso
/
SKIN
/
Le Crapouillot.wmz
/
WMPANImagix.JS
< prev
next >
Wrap
Text File
|
2002-01-19
|
16KB
|
698 lines
/*
WMPAniMagiX
script library for animations or screenmates in WMP
(c) 2002 X.Singy, http://www.singyfamily.com, xavier@singyfamily.com
This library is free software; you can redistribute it and/or
modify it under the terms of the GNU Lesser General Public
License as published by the Free Software Foundation; either
version 2.1 of the License, or (at your option) any later version.
This library is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
Lesser General Public License for more details.
You should have received a copy of the GNU Lesser General Public
License along with this library; if not, write to the Free Software
Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
or check here: http://www.gnu.org/copyleft/lesser.html
*/
/* sprite objects */
/******************/
function sprite(initState, initScenario, x, y, z,minX,minY,maxX,maxY){
this.pos = new pos(x,y,z,minX,minY,maxX,maxY);
this.status= new status( 0,initState,initScenario );
}
function pos(x,y,z,minX,minY,maxX,maxY){
this.x=x;
this.y=y;
this.x2 = x;
this.y2 = y;
this.z=z;
this.maxX = maxX;
this.maxY = maxY;
this.minX = minX;
this.minY = minY;
this.width = 0;
this.height = 0;
}
function status(
step_no,
current_state_name,
current_scenario_name
){
this.step_no=step_no;
this.current_state_name=current_state_name;
this.current_scenario_name=current_scenario_name;
this.timeout = 0;
this.touched = false;
this.touching = new Array;
}
function state(){
this.isReady=false;
this.z=0;
this.scenarios= new Array;
this.default_ontouch_next_states = new Array;
this.onErrorScenario= "" ;
this.absolutePos=false ;
}
function scenario(){
this.random_delay = 0;
this.onclick_zones = new Array;
this.onmouseover_zones = new Array;
this.steps= new Array;
this.next_scenarios = new Array;
this.next_states = new Array;
this.ontop_next_states = new Array;
this.onbottom_next_states = new Array;
this.onleft_next_states = new Array;
this.onright_next_states = new Array;
this.ontouch_next_states = new Array;
}
function on_zone( x, y, dx, dy ){
this.x=x;
this.y=y;
this.dx=dx;
this.dy=dy;
this.next_states = new Array;
}
function step( state_name, image, dx, dy, delay) {
this.image= image;
this.delay= delay;
this.dx=dx;
this.dy=dy;
}
function next_scenario( scenario_name, probability ) {
this.scenario_name = scenario_name;
this.probability = probability;
}
function next_state( state_name, scenario_name, probability ) {
this.state_name = state_name;
this.scenario_name = scenario_name;
this.probability = probability;
this.action = null;
}
function success(){
states[this.state_name].q_images_to_get--;
}
/* anim scripts */
/****************/
function AMXrnd() {
AMXrnd.seed = (AMXrnd.seed*9301+49297) % 233280;
return AMXrnd.seed/(233280.0);
}
function AMXmove(sid,sx,sy,sz){
//printToDebug("AMXmov( "+ sid +","+ sx +","+ sy +","+ sz +")" );
evalString="AMXSubviewSprite" + sid + ".moveTo(" + sx + "," + sy + "," + AMXMoveTime+ ");" ;
//printToDebug(evalString);
eval(evalString);
return;
}
function AMXswap(n,img){
evalString="AMXSubviewSprite" + n + ".backgroundImage='" + img+ "';" ;
//printToDebug(evalString);
eval(evalString);
//printToDebug(" quit AMXswap( "+ n +"," + img + ")" );
return;
}
function getRandomSelection(objects ){
p = 0;
for (ilo=0;ilo<objects.length;ilo++) {
p += objects[ilo].probability;
}
r = AMXrnd()*p;
p=0 ;
selected = false ;
for (ilo=0; ilo<objects.length && !selected ;ilo++) {
p += objects[ilo].probability;
if (r<p) {
return ilo;
}
}
return objects.length;
}
function checkPos( sp ) {
//printToDebug("checkPos( "+ sp +")" );
cState = sp.status.current_state_name;
cScenario = sp.status.current_scenario_name ;
with (states[ cState ].scenarios[ cScenario ] ) {
with (sp.pos) {
found = false;
if (x + width >maxX) {
onborder_next_states = onright_next_states;
if ( onborder_next_states.length>0 ) found= true;
} else
if (x<minX) {
onborder_next_states = onleft_next_states;
if ( onborder_next_states.length>0 ) found= true;
}
if (y + height >maxY) {
if (!found)
onborder_next_states = onbottom_next_states;
else
if (AMXrnd() > win_width/(win_height+win_width) ) {
onborder2_next_states = onbottom_next_states;
if ( onborder2_next_states.length>0 )
onborder_next_states = onborder2_next_states;
} else {
//keep previous direction
}
if ( onborder_next_states.length>0 ) found= true;
} else
if (y<minY) {
if (!found)
onborder_next_states = ontop_next_states;
else
if (AMXrnd() > win_width/(win_height+win_width) ) {
onborder2_next_states = ontop_next_states;
if ( onborder2_next_states.length>0 )
onborder_next_states = onborder2_next_states;
} else {
//keep previous direction
}
if ( onborder_next_states.length>0 ) found= true;
}
if (!found) {
//printToDebug(" - no border touched" );
return;
}
if (changeState(sp, cState, cScenario, onborder_next_states)) return;
} // with sp.pos
} // with states
//printToDebug(" - done checkPos( "+ sp +")" );
return;
}
function checkTouch(nn){
//printToDebug("checkTouch( "+ nn +")" );
if (AMXq==0) return;
checkTouchN ++;
if (checkTouchN > checkTouchEveryQ ) {
checkTouchEveryQ = AMXq/4 + 1;
checkTouchN = 0;
for (ito=0;ito<AMXq;ito++){
with (AMXs[ito].pos) {
x2 = x + defaultSpriteWidth ;
y2 = y + defaultSpriteHeight ;
}
}
atouched = false;
for (il=0;il<AMXq;il++){
if ( !(il == nn) && (AMXs[il].status.touched == false) ) {
if ( isInBounds( AMXs[il].pos.x , AMXs[il].pos.x2, AMXs[nn].pos.x, AMXs[nn].pos.x2) ) {
if ( isInBounds( AMXs[il].pos.y , AMXs[il].pos.y2, AMXs[nn].pos.y, AMXs[nn].pos.y2) ) {
if (AMXs[nn].status.touched == false) {
if (!atouched) doTouch(nn,il);
doTouch(il,nn);
AMXs[il].status.touched = true;
atouched = true;
}
}
}
}
}
AMXs[nn].status.touched = atouched;
}
return;
}
function doTouch(tt,tt2) {
printToDebug( tt + " touched " + tt2 );
sp = AMXs[tt];
sp2 = AMXs[tt2];
cState = sp.status.current_state_name;
cScenario = sp.status.current_scenario_name ;
with (states[ cState ].scenarios[ cScenario ] ) {
states2=ontouch_next_states[sp2.status.current_state_name] ;
// if (states2+"" == "undefined") {
if (!states2) {
states2 = states[ cState ].default_ontouch_next_states[sp2.status.current_state_name];
// if (states2+"" == "undefined") {
if (!states2) {
states2 = new Array;
}
}
if (changeState(sp, cState, cScenario, states2 )) {
printToDebug( " - leaving ");
return;
} else {
}
}
printToDebug( " - leaving ");
}
function isInBounds(l1,u1,l2,u2) {
//printToDebug("isInBounds...)" );
return ( ((l1<l2) && (l2<u1)) || ((l1< u2) && (u2<u1)) );
}
function changeState(sp, cState, cScenario, next_states_choice) {
//printToDebug("changeState( "+ sp +","+ cState +","+ cScenario +")" );
if (next_states_choice.length==0) return false;
sel = getRandomSelection(next_states_choice);
if ( cState == next_states_choice[sel].state_name && cScenario == next_states_choice[sel].scenario_name) {
return false;
} else {
sp.status.current_state_name = next_states_choice[sel].state_name ;
sp.status.current_scenario_name = next_states_choice[sel].scenario_name ;
sp.pos.z = states[ sp.status.current_state_name ].z;
sp.status.step_no = 0 ;
//removed for WMP
eval(next_states_choice[sel].action);
// //printToDebug(" ==> CHANGE : " + !(cState == sp.status.current_state_name ) );
return !(cState == sp.status.current_state_name );
} // else
// //printToDebug(" ==> no result" );
return;
}
function animate(n){
//printToDebug("animate( "+ n +")" );
sp = AMXs[n];
cStatus = sp.status;
cPos = sp.pos;
cState = cStatus.current_state_name ;
cScenario = cStatus.current_scenario_name ;
cStatus.step_no++;
with (states[ cState ].scenarios[ cScenario ] ) {
if (cStatus.step_no == steps.length) {
cStatus.step_no = 0 ;
//set next state
if (!changeState(sp, cState, cScenario, next_states) ) {
//set next scenario
sel = getRandomSelection(next_scenarios);
cStatus.current_scenario_name = next_scenarios[sel].scenario_name ;
checkTouch(n);
} else {
//alert("state/scenario has changed")
}
}
}
//scenario may have changed so, have to do with{} again
with (states[ cStatus.current_state_name ].scenarios[ cStatus.current_scenario_name ] ) {
printToDebug(" scenario: " + cStatus.current_scenario_name + " step no: " + cStatus.step_no + " - dx: " + steps[cStatus.step_no].dx );
if (states[ cStatus.current_state_name ].absolutePos) {
cPos.x = steps[ cStatus.step_no ].dx ;
cPos.y = steps[ cStatus.step_no ].dy ;
} else {
cPos.x = cPos.x + steps[ cStatus.step_no ].dx ;
cPos.y = cPos.y + steps[ cStatus.step_no ].dy ;
}
//check if out of limits
checkPos( sp );
//AMXmove
AMXmove( n , cPos.x, cPos.y, cPos.z );
}
//scenario may have changed so, have to do with{} again
with (states[ cStatus.current_state_name ].scenarios[ cStatus.current_scenario_name ] ) {
AMXswap( n , steps[ cStatus.step_no ].image );
if ( cStatus.current_scenario_name == "stop" ) {
AMXmove( n , -1000 , 0 );
cStatus.timeout=-1;
} else {
cStatus.timeout= steps[ cStatus.step_no ].delay + random_delay*AMXrnd() ;
}
}
//printToDebug("animate done ( "+ n +")" );
return;
}
var threadLock = false;
function masterThread(){
if (!initialized) {
if (debugAMX) debugView.visible="true";
if (mustMaximize) {
view.minimize();
view.maximize();
}
initialized=true;
win_height = view.height ;
win_width = view.width ;
initAnims();
//printToDebug('start timer interval');
// view.timerInterval=AMXinterval+50;
//XVS TEST
view.timerInterval=0;
timer.moveTo(250,200,AMXinterval);
}
//printToDebug("masterThread " + threadLock + " - " + AMXrnd() );
if (threadLock) {
//printToDebug("masterThread locked***" );
return;
}
threadLock = true;
for(mi=0;mi<AMXq;mi++) {
mcTimeout = AMXs[mi].status.timeout;
if (mcTimeout<-9999) {
//this one is stopped, do nothing
//printToDebug( "" + mi + " is stopped - do nothing" );
} else {
if (mcTimeout<1) {
//this one should be animated now
animate(mi);
} else {
//this shouldn't be animated now. Just decrease counter
//printToDebug( "" + mi + " is paused - wait" );
AMXs[mi].status.timeout = mcTimeout - AMXtimeoutDecrement;
}
}
}
timeoutCount++;
threadLock = false;
return;
}
timerStatus=0;
function moveTimer(){
if (timerStatus==0) {
timerStatus=1;
timer.moveTo(-200,200,AMXinterval);
} else {
timerStatus=0;
timer.moveTo(-250,200,AMXinterval);
}
masterThread();
}
function checkOnMouseOver(n){
//printToDebug("checkOnMouseOver( "+ n +")" );
sp = AMXs[n];
cState = sp.status.current_state_name;
cScenario = sp.status.current_scenario_name;
//printToDebug(" curren state/scenario: "+ cState +","+ cScenario +")" );
with (states[ cState ].scenarios[ cScenario ] ) {
xDelta=event.offsetX ;
yDelta=event.offsetY ;
if (onmouseover_zones.length == 0) {
//printToDebug(" no zone defined" );
return
} else {
for (i=0;i<onmouseover_zones.length;i++) {
with ( onmouseover_zones[i] ) {
//printToDebug("change? x,y:" + x + "," + y + " xDelta,yDelta: " + xDelta + "," + yDelta + " dx,dy : " + dx + "," + dy);
if ( (xDelta > x) && (yDelta > y) && (xDelta-x < dx) && (yDelta-y < dy) ) {
//printToDebug("yes");
changeState(sp, cState, cScenario, next_states)
sp.status.step_no = -1;
sp.status.timeout = 0;
return;
}
}
}
}
}
}
function checkOnClick(n){
//printToDebug("checkOnClick( "+ n +")" );
sp = AMXs[n];
cState = sp.status.current_state_name;
cScenario = sp.status.current_scenario_name;
with (states[ cState ].scenarios[ cScenario ] ) {
xDelta=event.offsetX ;
yDelta=event.offsetY ;
//printToDebug( cState );
//printToDebug( cScenario );
//printToDebug("x:"+ xDelta );
//printToDebug("y:"+ yDelta );
if (onclick_zones.length == 0) {
//printToDebug("no action");
return
} else {
for (iz=0;iz<onclick_zones.length;iz++) {
with ( onclick_zones[iz] ) {
//printToDebug("change? x,y:" + x + "," + y + " xDelta,yDelta: " + xDelta + "," + yDelta + " dx,dy : " + dx + "," + dy);
if ( (xDelta > x) && (yDelta > y) && (xDelta-x < dx) && (yDelta-y < dy) ) {
//printToDebug("yes");
if (changeState(sp, cState, cScenario, next_states) )
sp.status.step_no = -1;
sp.status.timeout = 0;
return;
}
}
}
}
}
}
function initAnims() {
//printToDebug('initanims');
initStates();
//win_height = 600 ;
// win_width = 800 ;
//body_height = win_height;
//body_width = win_width ;
setSpriteObjects();
}
function printToDebug(m){
if (!debugAMX) return;
debugLinesCursor++ ;
debugCount++;
if (!(debugLinesCursor<debugLinesMax)) debugLinesCursor=0;
debugLines[debugLinesCursor] = debugCount +": " + m;
debugString="";
for (i=debugLinesCursor+1 ; i < debugLinesMax ; i++ ) {
debugString += debugLines[i] + "\n";
}
for (i= 0; i <debugLinesCursor+1 ; i++){
debugString += debugLines[i] + "\n";
}
debug.value=debugString;
}
//ADDED for WMP
var initialized=false;
//initial values
var win_height;
var win_width;
var images_array = new Array;
var AMXs = new Array;
var checkTouchEveryQ = 0;
var checkTouchN = 0;
var noStatusChange =false;
var animStarted = false;
var timeoutCount = 0;
AMXrnd.today=new Date();
AMXrnd.seed=AMXrnd.today.getTime();
//REMOVED for WMP
//var delta_images = document.images.length;
//document.writeln(AMXspritesHTML());
if (debugAMX) {
var debugLinesMax= 20;
var debugLines = new Array ;
var debugCount =0 ;
for (i=0;i<debugLinesMax;i++) {
debugLines[i] = "";
}
var debugLinesCursor=0;
}
//REMOVED for WMP - put in the skin file
//window.onload = initAnims;